package com.ruoyi.web.controller.production.carton;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import com.ruoyi.production.domain.carton.CartonPurchaseApply;
import com.ruoyi.production.service.carton.ICartonPurchaseApplyService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 纸箱购买申请Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/system/cartonApply")
public class CartonPurchaseApplyController extends BaseController
{
    @Autowired
    private ICartonPurchaseApplyService cartonPurchaseApplyService;

    /**
     * 查询纸箱购买申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:cartonApply:list')")
    @GetMapping("/list")
    @ApiOperation("查询纸箱购买申请列表")
    public TableDataInfo list(CartonPurchaseApply cartonPurchaseApply)
    {
        startPage();
        List<CartonPurchaseApply> list = cartonPurchaseApplyService.selectCartonPurchaseApplyList(cartonPurchaseApply);
        return getDataTable(list);
    }

    /**
     * 导出纸箱购买申请列表
     */
    @PreAuthorize("@ss.hasPermi('system:cartonApply:export')")
    @Log(title = "纸箱购买申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CartonPurchaseApply cartonPurchaseApply)
    {
        List<CartonPurchaseApply> list = cartonPurchaseApplyService.selectCartonPurchaseApplyList(cartonPurchaseApply);
        ExcelUtil<CartonPurchaseApply> util = new ExcelUtil<CartonPurchaseApply>(CartonPurchaseApply.class);
        return util.exportExcel(list, "纸箱购买申请数据");
    }

    /**
     * 获取纸箱购买申请详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cartonApply:query')")
    @GetMapping(value = "/{cartonPurchaseApplyId}")
    public AjaxResult getInfo(@PathVariable("cartonPurchaseApplyId") Long cartonPurchaseApplyId)
    {
        return AjaxResult.success(cartonPurchaseApplyService.selectCartonPurchaseApplyById(cartonPurchaseApplyId));
    }

    /**
     * 新增纸箱购买申请
     */
    @PreAuthorize("@ss.hasPermi('system:cartonApply:add')")
    @Log(title = "纸箱购买申请", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增纸箱购买申请")
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody CartonPurchaseApply cartonPurchaseApply)
    {
        return toAjax(cartonPurchaseApplyService.insertCartonPurchaseApply(cartonPurchaseApply));
    }

    /**
     * 修改纸箱购买申请
     */
    @PreAuthorize("@ss.hasPermi('system:cartonApply:edit')")
    @Log(title = "纸箱购买申请", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改纸箱购买申请")
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody CartonPurchaseApply cartonPurchaseApply)
    {
        return toAjax(cartonPurchaseApplyService.updateCartonPurchaseApply(cartonPurchaseApply));
    }

    /**
     * 删除纸箱购买申请
     */
    @PreAuthorize("@ss.hasPermi('system:cartonApply:remove')")
    @Log(title = "纸箱购买申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cartonPurchaseApplyIds}")
    public AjaxResult remove(@PathVariable Long[] cartonPurchaseApplyIds)
    {
        return toAjax(cartonPurchaseApplyService.deleteCartonPurchaseApplyByIds(cartonPurchaseApplyIds));
    }
}
